package cn.max.web.utils;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 *@author Val.(Valentine Vincent) E-mail:valer@126.com
 *@version 1.0
 *@date 2014-7-22
 *Instruction : 
 **/
public class FileItemUtil {

	public List<FileItem> getFiles(HttpServletRequest request) throws FileUploadException {
		
		@SuppressWarnings("unchecked")
		List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
		
		List<FileItem> list = new ArrayList<FileItem>();
		for (FileItem fi : items) {
			if (fi.isFormField()) {
				continue;
			}
			
			list.add(fi);
		}
		
		return list;
		
	}
	
}
